Imports Microsoft.VisualBasic
Imports Oracle.DataAccess.Client
Imports Oracle.DataAccess.Types
Imports System.Data
Imports DataAccesGenerales
Imports DataAcces

Public Class DataAccesPesajeAduana_Detalle
	Private Const consTimeOut As Integer = 0 

    ''' <summary>
    ''' Funcion para Insertar un regristro en la tabla PesajeAduana_Detalle
    ''' </summary>
	Public Function PesajeAduana_Detalle_InsertarModificar(pnidpesaje As Long, pfolio_pesaje As String, pfolio_autoriza As String, ptipo_trans_adu As Integer, pclave_pesador As String, pnum_cs_aa As Integer, ppeso_vacio As Double, ppeso_lleno As Double, ppeso_neto As Double, pbascula_vacio As Double, pbascula_lleno As Double, pfecha_mod As String, pfecha_ini As String, pfecha_fin As String, pfecha_termino As String, phora_mod As String, phora_ini As String, phora_fin As String, pplacas As String, ptipo_maniobra As String, pstatus As String, penvio As String, pobservaciones As String) As Byte
        Dim pTransaccion As Byte = 0
        Dim mensaje As String = String.Empty
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.PesajeAduana_DetalleInsertarModificar"
          oraCommandDocumentos.Parameters.Add("pnidpesaje", pnidpesaje)
          oraCommandDocumentos.Parameters.Add("pfolio_pesaje", pfolio_pesaje)
          oraCommandDocumentos.Parameters.Add("pfolio_autoriza", pfolio_autoriza)
          oraCommandDocumentos.Parameters.Add("ptipo_trans_adu", ptipo_trans_adu)
          oraCommandDocumentos.Parameters.Add("pclave_pesador", pclave_pesador)
          oraCommandDocumentos.Parameters.Add("pnum_cs_aa", pnum_cs_aa)
          oraCommandDocumentos.Parameters.Add("ppeso_vacio", ppeso_vacio)
          oraCommandDocumentos.Parameters.Add("ppeso_lleno", ppeso_lleno)
          oraCommandDocumentos.Parameters.Add("ppeso_neto", ppeso_neto)
          oraCommandDocumentos.Parameters.Add("pbascula_vacio", pbascula_vacio)
          oraCommandDocumentos.Parameters.Add("pbascula_lleno", pbascula_lleno)
          oraCommandDocumentos.Parameters.Add("pfecha_mod", pfecha_mod)
          oraCommandDocumentos.Parameters.Add("pfecha_ini", pfecha_ini)
          oraCommandDocumentos.Parameters.Add("pfecha_fin", pfecha_fin)
          oraCommandDocumentos.Parameters.Add("pfecha_termino", pfecha_termino)
          oraCommandDocumentos.Parameters.Add("phora_mod", phora_mod)
          oraCommandDocumentos.Parameters.Add("phora_ini", phora_ini)
          oraCommandDocumentos.Parameters.Add("phora_fin", phora_fin)
          oraCommandDocumentos.Parameters.Add("pplacas", pplacas)
          oraCommandDocumentos.Parameters.Add("ptipo_maniobra", ptipo_maniobra)
          oraCommandDocumentos.Parameters.Add("pstatus", pstatus)
          oraCommandDocumentos.Parameters.Add("penvio", penvio)
          oraCommandDocumentos.Parameters.Add("pobservaciones", pobservaciones)

                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add("pMensaje", Oracle.DataAccess.Client.OracleDbType.Varchar2, 200).Direction = ParameterDirection.Output

                    oraConnection.Open()
                    oraCommandDocumentos.ExecuteNonQuery()
                    pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    mensaje = oraCommandDocumentos.Parameters("pMensaje").Value.ToString()
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return pTransaccion
    End Function
  
    ''' <summary>
    ''' Funcion para consultar un registro de la tabla PesajeAduana_Detalle
    ''' </summary>
    ''' <param name="pNidDocumento">numero de documento</param>
    ''' <returns>DataTable</returns>
    ''' <remarks></remarks>
   Public Function PesajeAduana_Detalle_Consultar(pNidDocumento As Long) As DataTable
        Dim dtResultado As New DataTable("PesajeAduana_DetalleConsulta")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.PesajeAduana_DetalleConsultar"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function
  
    ''' <summary>
    ''' Funcion para generar la cadena XML Chilkat del documento de la tabla PesajeAduana_Detalle
    ''' </summary>
    ''' <param name="nidDocumento"> numero del documento</param>
    ''' <returns>Chilkat.Xml</returns>
    ''' <remarks></remarks>
   Public Function PesajeAduana_Detalle_CadenaOriginalXMLChilkat(nidDocumento As Long) As Chilkat.Xml
        Dim detalleDataSet As New DataSet("DatosPesajeAduana_Detalle")
        Try
      detalleDataSet = PesajeAduana_Detalle_DetalleXML(nidDocumento)
            'En esta parte van las tablas obtenidas en la consulta anterior
            'separadas dependiendo del reporte a crear
            detalleDataSet.Tables(0).TableName = "Informacion del Tramite"
            detalleDataSet.Tables(1).TableName = "Datos PesajeAduana_Detalle"
            detalleDataSet.Tables(2).TableName = "Archivos Anexos"
            detalleDataSet.Tables(3).TableName = "Incidencias"

            Dim xml As New Chilkat.Xml
            xml.LoadXml(detalleDataSet.GetXml())
            Return xml 'detalleDataSet.GetXml()
        Catch ex As Exception
            Throw ex
        End Try
    End Function

    ''' <summary>
    ''' Funcion para consultar el detalle del documento de la tabla PesajeAduana_Detalle
    ''' </summary>
    ''' <param name="pNidDocumento">numero del documento</param>
    ''' <returns>DataSet</returns>
    ''' <remarks></remarks>
	Public Function PesajeAduana_Detalle_DetalleXML(pNidDocumento As Long) As DataSet
        Dim dsDetalle As New DataSet("PesajeAduana_DetalleDetalle")
        Dim pTransaccion As Byte = 0
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.PesajeAduana_DetalleDetalleXML"
                    oraCommandDocumentos.Parameters.Add("pNidDocumento", pNidDocumento)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pEncabezado", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pDatos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pAnexos", OracleDbType.RefCursor)).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pIncidencias", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    'pTransaccion = CByte(oraCommandDocumentos.Parameters("pTransaccion").Value.ToString())
                    oraDataAdapter.Fill(dsDetalle)
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dsDetalle
    End Function
  
	Public Function PesajeAduana_Detalle_DatosBase() As DataSet
        Dim dtResultado As New DataSet("PesajeAduana_Detalle_DatosBase")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.PesajeAduana_DetalleDatosBase"
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function

    ''' <summary>
    ''' Funcion para generar un combo de la tabla PesajeAduana_Detalle
    ''' </summary>
    ''' <param name="pNombre">nombre a buscar en la tabla</param>
    ''' <returns>DataTable</returns>
    ''' <remarks>si el nombre es "" retornara todos los registros</remarks>
	Public Function PesajeAduana_Detalle_Combo(pNombre As String) As DataTable
        Dim dtResultado As New DataTable("PesajeAduana_DetalleCombo")
        Try
            Using oraConnection As New Oracle.DataAccess.Client.OracleConnection(ConfigurationManager.ConnectionStrings("EDIV2DESOraClient").ConnectionString)
                Using oraCommandDocumentos As New Oracle.DataAccess.Client.OracleCommand()
                    oraCommandDocumentos.Connection = oraConnection
                    oraCommandDocumentos.CommandTimeout = consTimeOut
                    oraCommandDocumentos.CommandType = CommandType.StoredProcedure
                    oraCommandDocumentos.CommandText = "EDIV2.?NomPaquete.PesajeAduana_DetalleCombo"
                    oraCommandDocumentos.Parameters.Add("pNombre", pNombre)
                    oraCommandDocumentos.Parameters.Add("pTransaccion", Oracle.DataAccess.Client.OracleDbType.Byte).Direction = ParameterDirection.Output
                    oraCommandDocumentos.Parameters.Add(New Oracle.DataAccess.Client.OracleParameter("pCursor", OracleDbType.RefCursor)).Direction = ParameterDirection.Output

                    Dim oraDataAdapter As New OracleDataAdapter(oraCommandDocumentos)
                    oraDataAdapter.Fill(dtResultado)
                    oraConnection.Close()
                End Using
            End Using
        Catch ex As Exception
            Throw ex
        End Try
        Return dtResultado
    End Function

End Class
